home *** CD-ROM | disk | FTP | other *** search
- head 2.2;
- access;
- symbols
- C_2:2.2
- C_1:1.2;
- locks; strict;
- comment @ * @;
-
-
- 2.2
- date 93.11.30.22.42.33; author Aussem; state Exp;
- branches;
- next 2.1;
-
- 2.1
- date 93.11.23.19.58.39; author Aussem; state Exp;
- branches;
- next 1.3;
-
- 1.3
- date 93.11.20.20.38.55; author Aussem; state Exp;
- branches;
- next 1.2;
-
- 1.2
- date 93.09.18.16.47.47; author Aussem; state Exp;
- branches;
- next 1.1;
-
- 1.1
- date 93.09.08.16.27.13; author Aussem; state Exp;
- branches;
- next ;
-
-
- desc
- @analyse and return the path
- @
-
-
- 2.2
- log
- @fixed a bug in searching the last host in path file
- @
- text
- @/*
- * getpath.c
- *
- * Routines to lookup path for an address
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * $Log: getpath.c,v $
- * Revision 2.1 1993/11/23 19:58:39 Aussem
- * Version 2.0 check in
- *
- * Revision 1.3 1993/11/20 20:38:55 Aussem
- * extended Debug options
- *
- * Revision 1.2 1993/09/18 16:47:47 Aussem
- * insert GNU license text in the header
- *
- * Revision 1.1 1993/09/08 16:27:13 Aussem
- * Initial revision
- *
- *
- */
-
- static char *rcsid="$Id: getpath.c,v 2.1 1993/11/23 19:58:39 Aussem Exp Aussem $";
-
- # include <stdio.h>
- # include <sys/types.h>
- # include <ctype.h>
- # include "defs.h"
-
- extern enum edebug debug; /* how verbose we are */
- extern char *pathfile; /* location of path database */
-
- /*
- **
- ** getpath(): look up key in ascii sorted path database.
- **
- */
-
- getpath( key, path , cost)
- char *key; /* what we are looking for */
- char *path; /* where the path results go */
- int *cost; /* where the cost results go */
- {
- long pos, middle, hi, lo;
- static long pathlength = 0;
- register char *s;
- int c;
- static FILE *file;
- int flag;
-
- print_error(NOTICE,"looking for '%s'\n", key);
-
- if(pathlength == 0) { /* open file on first use */
- if((file = fopen(pathfile, "r")) == NULL) {
- (void) printf("can't access %s.\n", pathfile);
- pathlength = -1;
- } else {
- (void) fseek(file, 0L, 2); /* find length */
- pathlength = ftell(file);
- }
- }
- if( pathlength == -1 )
- return( EX_OSFILE );
-
- lo = 0;
- hi = pathlength;
- (void) strcpy( path, key );
- (void) strcat( path, "\t" );
- /*
- ** "Binary search routines are never written right the first time around."
- ** - Robert G. Sheldon.
- */
- for( ;; ) {
- pos = middle = ( hi+lo+1 )/2;
- (void) fseek(file, pos, 0); /* find midpoint */
- if(pos != 0)
- while(((c = getc(file)) != EOF) && (c != '\n'))
- ; /* go to beginning of next line */
- if(c == EOF) {
- return(EX_NOHOST);
- }
- for( flag = 0, s = path; flag == 0; s++ ) { /* match??? */
- if( *s == '\0' ) {
- goto solved;
- }
- if((c = getc(file)) == EOF) {
- break; /* actions will be taken in "close window" part */
- }
- flag = lower(c) - lower(*s);
- }
- if(lo >= middle) { /* failure? */
- return(EX_NOHOST);
- }
- if((c != EOF) && (flag < 0)) { /* close window */
- lo = middle;
- } else {
- hi = middle - 1;
- }
- }
- /*
- ** Now just copy the result.
- */
- solved:
- while(((c = getc(file)) != EOF) && (c != '\t') && (c != '\n')) {
- *path++ = c;
- }
- *path = '\0';
- /*
- ** See if the next field on the line is numeric.
- ** If so, use it as the cost for the route.
- */
- if(c == '\t') {
- int tcost = -1;
- while(((c = getc(file)) != EOF) && isdigit(c)) {
- if(tcost < 0) tcost = 0;
- tcost *= 10;
- tcost += c - '0';
- }
- if(tcost >= 0) *cost = tcost;
- }
- return (EX_OK);
- }
- @
-
-
- 2.1
- log
- @Version 2.0 check in
- @
- text
- @d21 3
- d36 1
- a36 1
- static char *rcsid="$Id: getpath.c,v 1.3 1993/11/20 20:38:55 Aussem Exp Aussem $";
- d100 1
- a100 1
- return(EX_NOHOST);
- @
-
-
- 1.3
- log
- @extended Debug options
- @
- text
- @d21 3
- d33 1
- a33 1
- static char *rcsid="$Id: getpath.c,v 1.2 1993/09/18 16:47:47 Aussem Exp Aussem $";
- @
-
-
- 1.2
- log
- @insert GNU license text in the header
- @
- text
- @d21 3
- d30 1
- a30 1
- static char *rcsid="$Id: getpath.c,v 1.1 1993/09/08 16:27:13 Aussem Exp Aussem $";
- d58 1
- a58 1
- DEBUG("getpath: looking for '%s'\n", key);
- @
-
-
- 1.1
- log
- @Initial revision
- @
- text
- @d6 4
- a9 1
- * $Log$
- d11 14
- d27 1
- a27 1
- static char *rcsid="$Id$";
- @
-